﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>PixelGetColor - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The PixelGetColor function retrieves the color of the pixel at the specified x,y coordinates." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>PixelGetColor</h1>

<p>Retrieves  the color of the pixel at the specified x,y coordinates.</p>

<pre class="Syntax">Color := <span class="func">PixelGetColor</span>(X, Y <span class="optional">, Mode</span>)</pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>X, Y</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>The X and Y coordinates of the pixel. Coordinates are relative to the active window unless <a href="CoordMode.htm">CoordMode</a> was used to change that.</p>
  </dd>

  <dt>Mode</dt>
  <dd>
      <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
      <p>This parameter may contain zero or more of the following words. If more than one word is present, separate each from the next with a space (e.g. <code>"Alt Slow"</code>).</p>
      <p><strong>Alt</strong>: Uses an alternate method to retrieve the color, which should be used when the normal method produces invalid or inaccurate colors for a particular type of window. This method is about 10% slower than the normal method.</p>
      <p><strong>Slow</strong>: Uses a more elaborate method to retrieve the color, which may work in certain full-screen applications when the other methods fail. This method is about three times slower than the normal method. Note: <em>Slow</em> takes precedence over <em>Alt</em>, so there is no need to specify <em>Alt</em> in this case.</p>
    </dd>

</dl>

<h2 id="Return_Value">返回值</h2>
<p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
<p>This function returns a hexadecimal numeric string representing the RGB (red-green-blue) color of the pixel. 例如, the color purple is defined 0x800080 because it has an intensity of 0x80 (128) for its blue and red components but an intensity of 0x00 (0) for its green component.</p>

<h2 id="Error_Handling">错误处理</h2>
<p>An exception is thrown if there was a problem retrieving the pixel's color.</p>

<h2 id="Remarks">备注</h2>
<p>The pixel must be visible; in other words, it is not possible to retrieve the pixel color of a window hidden behind another window. By contrast, pixels beneath the mouse cursor can usually be detected. The exception to this is game cursors, which in most cases will hide any pixels beneath them.</p>
<p>Use Window Spy (available in tray icon menu) or the example at the bottom of this page to determine the colors currently on the screen.</p>
<p>Known limitations:</p>
<ul>
  <li>A window that is <a href="WinSetTransparent.htm">partially transparent</a> or that has one of its colors marked invisible (<a href="WinSetTransColor.htm">WinSetTransColor</a>) typically yields colors for the window behind itself rather than its own.</li>
  <li>PixelGetColor might not produce accurate results for certain applications. If this occurs, try specifying the word <em>Alt</em> or <em>Slow</em> in the last parameter.</li>
</ul>
<h2 id="Related">相关</h2>
<p><a href="PixelSearch.htm">PixelSearch</a>, <a href="ImageSearch.htm">ImageSearch</a>, <a href="CoordMode.htm">CoordMode</a>, <a href="MouseGetPos.htm">MouseGetPos</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>^!z::  <em>; Control+Alt+Z hotkey.</em>
MouseGetPos MouseX, MouseY
MsgBox "The color at the current cursor position is " PixelGetColor(MouseX, MouseY)
return</pre>
</div>

</body>
</html>